<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/common/common_css :: commonHeader('类别管理')"></head>
<link th:href="@{/js/admin.ui/lib/jquery.treetable/jquery.treetable.css}" rel="stylesheet" type="text/css" />
<link th:href="@{/js/admin.ui/lib/kkpager/kkpager_blue.css}" rel="stylesheet" type="text/css" />
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe62e;</i> 系统管理
    <span class="c-gray en">&gt;</span> 作物类别
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>
<div class="page-container">
    <div class="text-c" style="text-align: center;">
        <form id="q_form" onsubmit="reloadPageSizeData();return false;">
            名称：<input type="text" id="q_name" name="q_name" placeholder="类别名称" class="input-text" style="width:200px"/>

            &nbsp;
            &nbsp;
            <button type="submit" class="btn btn-success radius">
                <i class="Hui-iconfont">&#xe665;</i> 搜索类别
            </button>
            &nbsp;
        </form>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
					<a href="javascript:gotoAddPage();" class="btn btn-success radius">
						<i class="Hui-iconfont">&#xe600;</i> 添加
					</a>
                    <!--<a href="javascript:exportRoleInfo();" class="btn btn-primary radius">-->
                    <!--<i class="Hui-iconfont">&#xe644;</i> 导出-->
                    <!--</a>-->
					<a href="javascript:deleteBatchUser();" class="btn btn-danger radius">
						<i class="Hui-iconfont">&#xe6e2;</i> 批量删除
					</a>
				</span>
        <span class="r" id="pageSizeSpan">
					页面显示
					<select id="pageSizeSelect" style="height: 25px; font-size: 14px;" onchange="javascript:reloadPageSizeData();">
						<option value="10">10</option>
						<option value="25">25</option>
						<option value="50">50</option>
						<option value="100">100</option>
					</select>
					条数据
					,
					共<span id="totalRecordsSpan"></span>条数据
				</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg" id="dataTable">
            <thead>
            <tr>
                <th style="text-align: center;">
                    <input type="checkbox" />
                </th>
                <th>类别id</th>
                <th>类别名称</th>
                <th style="text-align: center;">操作</th>
            </tr>
            </thead>
            <tbody id="dataTableBody">
            </tbody>
            <tfoot>
            <tr>
                <td colspan="4">
                    <div id="kkpager"></div>
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
    <form id="exportForm" action="export.action" method="post">
        <input type="hidden" name="roleName" id="export_q_roleName"/>
        <input type="hidden" name="roleDesc" id="export_q_roleDesc"/>
    </form>
</div>



<div th:include="admin/common/common_js :: onLoadJS"></div>
<script type="text/javascript" th:src="@{/js/admin.ui/lib/kkpager/kkpager.min.js}"></script>
<script type="text/javascript">
    $("#dataTable tbody").on("mousedown", "tr", function() {
        $(".selected").not(this).removeClass("selected");
        $(this).toggleClass("selected");
    });

    // 加载dataTable数据
    function selectDataTableData(pageNo, pageSize) {
        send(
            '/pestdiagnosis/sys/pest/listCropType',
            {
                'pageNo': pageNo,
                'pageSize': pageSize,
                'name': $.trim($('#name').val())
            },
            function (data) {
                if(data.result == 0) {
                    var dataTableData = '';
                    $.each(data.data, function (index, val) {
                        dataTableData +=
                            '<tr>'
                            + ' <td style="text-align: center;"><input type="checkbox" value="' + val.id + '" name="roleIdCheckBox" /></td>'
                            + '	<td>' + val.id + '</td>'
                            + '	<td>' + val.name + '</td>'
                            + ' <td style="text-align: center;">'
                            + '		<a title="编辑" href="javascript:;" onclick="javascript:gotoEditPage(' + val.id + ',\'' + val.name + '\');" style="text-decoration:none">'
                            + '			<i class="Hui-iconfont">&#xe6df;</i>'
                            + '		</a>'
                            + '		<a title="删除" href="javascript:;" onclick="javascript:deleteUser(' + val.id + ')" class="ml-5" style="text-decoration:none">'
                            + '			<i class="Hui-iconfont">&#xe6e2;</i>'
                            + '		</a>'
                            + '	</td>'
                            + '</tr>';
                    });
                    $("#dataTableBody").empty();
                    $("#dataTableBody").append(dataTableData);
                    var kkpagerObj = eval('(' + data.message + ')');
                    createPager(kkpagerObj.pno, kkpagerObj.total, kkpagerObj.totalRecords);
                    $('#totalRecordsSpan').text(kkpagerObj.totalRecords);
                }
            },
            function (res) {

            }
        );

    }

    // 生成分页数据
    function createPager(pno, total, totalRecords) {
        //生成分页
        kkpager.generPageHtml({
            pno : pno,
            //总页码
            total : total,
            //总数据条数
            totalRecords : totalRecords,
            mode : 'click',
            click : function(n){
                selectDataTableData(n, $('#pageSizeSelect').val());
                this.selectPage(n);
                return false;
            }
        }, true);
    }

    // 切换每页显示数据条数重新加载数据
    function reloadPageSizeData() {
        selectDataTableData(1, $('#pageSizeSelect').val());
    }

    // 页面加载执行
    jQuery(function ($) {
        selectDataTableData(1, $('#pageSizeSelect').val());
    })

    // 进入添加角色页面
    function gotoAddPage() {
        var index = layer.open({
            type: 2,
            title: '添加分类',
            content: '/pestdiagnosis/sys/pest/toAddCropType'
        });
        layer.full(index);
    }

    // 进入编辑角色页面
    function gotoEditPage(id, typeName) {
        var index = layer.open({
            type: 2,
            title: '编辑【' + typeName + '】',
            content: '/pestdiagnosis/sys/pest/toEditCropType?id=' + id
        });
        layer.full(index);
    }

    // 删除角色信息
    function deleteUser(id) {
        var hitMessage = '确认要删除？';
        layer.confirm(hitMessage, {title:'系统消息'},function(index){
            send(
                '/pestdiagnosis/sys/pest/delCropType',
                {'id' : id},
                function (data) {
                    if(data.result == 0) {
                        layer.msg(data.message, {icon: 1,time: 1500}, function() {
                            window.location.href = "/pestdiagnosis/sys/pest/toListCropType";
                        });
                    } else {
                        layer.msg(data.message, {icon: 5,time: 1500});
                    }
                },
                function (res) {

                }
            );

        });
    }

    // 批量删除角色信息
    function deleteBatchUser() {
        var roleIdArr = shiro.form.getCheckBoxSelectValues('roleIdCheckBox');
        if(roleIdArr.length == 0) {
            layer.msg('请选择要操作的数据行', {icon: 5,time: 1500});
        } else {
            var hitMessage = '【系统提示】批量删除操作将会删除一个或多个您选择的，请谨慎操作，确认删除？';
            layer.confirm(hitMessage, {title:'系统消息'},function(index){
                send(
                    '/pestdiagnosis/sys/pest/batchDelCropType',
                    {'ids' : roleIdArr.join(',')},
                    function (data) {
                        if(data.result == 0) {
                            layer.msg(data.message, {icon: 1,time: 1500}, function() {
                                window.location.href = "/pestdiagnosis/sys/pest/toListCropType";
                            });
                        } else {
                            layer.msg(data.message, {icon: 5,time: 1500});
                        }
                    },
                    function (res) {

                    }
                );

            });
        }
    }

</script>
</body>
</html>